package com.lhn.springcloud.controller;


import com.lhn.springcloud.pojo.Dept;
import com.lhn.springcloud.service.DeptClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class DeptConsumerController {
    // 消费者不应该有 Service 层，那怎么拿到 Service ?

    // RestTemplate：提供多种便捷访问远程 http 服务的方法，简单的 restful 服务模板
    // 注册到 spring 中
    // RestTemplace 参数：（String url, Class<T> responseType, Object... uriVariables）

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private DeptClientService deptClientService = null;

    @GetMapping("/consumer/dept/get/{id}")
    public Dept get(@PathVariable Long id){
        return deptClientService.queryById(id);
    }

    @PostMapping("/consumer/dept/add")
    public boolean add(Dept dept ){
        return deptClientService.addDept(dept);
    }

    @GetMapping("/consumer/dept/list")
    public List<Dept> list(){
        return deptClientService.queryAll();
    }

}
